<?php
/*
*
* @package phpBB3
* @version $Id: rss.php,v 1.0 2007/11/15 14:19:15 mikov Exp $
* @copyright (c) phpbbchina.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
	exit;
}


/**
* parse a message
*/
function parse_message($row, $bbcode_options, $bbcode_uid, $bbcode_bitfield)
{
	global $board_url;

	$row = htmlspecialchars(generate_text_for_display($row, $bbcode_uid, $bbcode_bitfield, $bbcode_options));;

	// smilies contain relative URL, we need it to be absolute
	return str_replace('<img src="./', '<img src="' . $board_url . '/', $row);
}

/**
* create a date according to RFC 3339 or 822
*/
function format_date($timestamp)
{
	global $rss_type;
	if ($rss_type == 'atom')
	{
		// RFC 3339 for ATOM
		return date('Y-m-d\TH:i:s\Z', $timestamp);
	}
	else
	{
		// RFC 822 for RSS2
		return date('D, d M Y H:i:s O', $timestamp);
	}
}

function exit_with_header($output,$message='')
{
	global $db, $HTTP_SERVER_VARS;
	$db->sql_close();
	if (function_exists("getallheaders")) 
	{
		header("HTTP/1.1 $output");
	}
	else 
	{
		header('Status: '.$output);
	}
	$code = intval(substr($output,0,3));
	if ( ($code == 200) || ($code == 304) )
	{
		if (isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'])) 
		{
			header("Last-Modified: ".$HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']);
		}
		if (isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'])) 
		{
			header("Etag: ".$HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']);
		}
	}
	if(!empty($message)) 
	{
		header ('Content-Type: text/plain');
        echo $message;
	}
	exit;
}

?>